﻿Imports OMANE.Common.UI
Imports OMANE.Common
Imports System.ComponentModel
Imports System.Windows.Input
Imports PTIC_Util
Imports System.Collections.ObjectModel
Imports Microsoft.Practices.Prism.Commands

Namespace ViewModels
    Public Class ViewModelSynthese
        Inherits ViewModelCommand
        Implements IViewModelTabSection

        Dim _Data As Object


        Sub New()
            'initData()
        End Sub
        Private _Model As ModelTauxGarantis
        Public Sub New(ByVal Model As ModelTauxGarantis, ByVal DisplayName As String, ByVal Command As ICommand)
            MyBase.DisplayName = DisplayName
            _Model = Model
            Title = "SYNTHESE"

            initData()
        End Sub
        Private Sub initData()
            Dim src = {"benin", "cote divoire", "togo", "guinee", "senegal"}
            Dim rnd As New Random(Now.Millisecond)
            Dim q = From e In src
                    Select Label = e, Spending = 100 * rnd.NextDouble(), Budget = 100 * rnd.NextDouble()

            _Data = q.AsEnumerable()
        End Sub


        Private Shared Map As Dictionary(Of String, String)
        Private Shared Function GetMap() As Dictionary(Of String, String)
            If Map Is Nothing Then
                Map = New Dictionary(Of String, String)

                Map.Add("Tx_TechA", "Taux Technique (+ 1%)")
                Map.Add("Duree_Actu", "Duree Actuarielle (+ 1an)")
                Map.Add("TxNom_Actu", "Taux Nominal (+ 1%)")
                Map.Add("Tx_CommiContA", "Commission (+ 1%)")
                Map.Add("Tx_fraiGestA", "Frais de Gestion (+ 1%)")
                Map.Add("ST_Immo", "Immobilier (+ 10% CSR)")
                Map.Add("ST_Tr_age", "Tranche d'age C (+ 10% CSR)")

            End If
            Return Map
        End Function




        Public ReadOnly Property Data As IEnumerable
            Get
                Try
                    _Model = Locator.ModelStatic
                    Dim rnd As New Random(Now.Millisecond)
                    Dim src = _Model.ListeTraitements.TraitMoteurMethode1.simulations.SimulRadar

                    Dim SP_scenarioCentral = _Model.ListeTraitements.TraitMoteurMethode1.ScenarioCentral.resultats.SP

                    Dim maxv = Aggregate e In src Into Max(e.Value)
                    Dim minv = Aggregate e In src Into Min(e.Value)

                    Echelle = Math.Ceiling((Aggregate e In src Into Max(Math.Abs(e.Value - SP_scenarioCentral))) * 100)
                    Tick = 1
                    Dim q = From e In src
                            Select Label = GetMap(e.Key), Spending = CDbl(CDbl(100) * ((e.Value - minv) / (maxv - minv))), Budget = 100 * Math.Abs(e.Value - SP_scenarioCentral) 'CDbl(CDbl(100) * (e.Value / maxv))


                    Return q.AsEnumerable()
                Catch ex As Exception
                    Echelle = 100
                    Tick = 25
                    Return _Data
                    Return Nothing
                End Try
            End Get
        End Property

        'Private _Data As IEnumerable(Of SynthesePoint)
        'Public Property Data As IEnumerable(Of SynthesePoint)
        '    Get
        '        Return _Data
        '    End Get
        '    Set(ByVal value As IEnumerable(Of SynthesePoint))
        '        OnPropertyChanging("Data")
        '        Dim args As New PropertyChangeEventArgs(Of IEnumerable(Of SynthesePoint))(_Data, value)
        '        OnDataChange(args)
        '        _Data = args.NewValue
        '        OnPropertyChanged("Data")
        '    End Set
        'End Property
        'Protected Overridable Sub OnDataChange(ByVal args As PropertyChangeEventArgs(Of IEnumerable(Of SynthesePoint)))
        '    RaiseEvent DataChange(Me, args)
        'End Sub
        'Public Event DataChange As PropertyChangeEventHandler(Of IEnumerable(Of SynthesePoint))


        Private _Echelle As Double
        Public Property Echelle As Double
            Get
                Return _Echelle
            End Get
            Set(ByVal value As Double)
                OnPropertyChanging("Echelle")
                Dim args As New PropertyChangeEventArgs(Of Double)(_Echelle, value)
                OnEchelleChange(args)
                _Echelle = args.NewValue
                OnPropertyChanged("Echelle")
            End Set
        End Property
        Protected Overridable Sub OnEchelleChange(ByVal args As PropertyChangeEventArgs(Of Double))
            RaiseEvent EchelleChange(Me, args)
        End Sub
        Public Event EchelleChange As PropertyChangeEventHandler(Of Double)


        Private _Tick As Double
        Public Property Tick As Double
            Get
                Return _Tick
            End Get
            Set(ByVal value As Double)
                OnPropertyChanging("Tick")
                Dim args As New PropertyChangeEventArgs(Of Double)(_Tick, value)
                OnTickChange(args)
                _Tick = args.NewValue
                OnPropertyChanged("Tick")
            End Set
        End Property
        Protected Overridable Sub OnTickChange(ByVal args As PropertyChangeEventArgs(Of Double))
            RaiseEvent TickChange(Me, args)
        End Sub
        Public Event TickChange As PropertyChangeEventHandler(Of Double)



        Public Property IsClosable As Boolean Implements IViewModelTabSection.IsClosable
        Public Property Icone As String Implements Common.UI.IViewModelTabSection.Icone
        Public Property Title As String Implements Common.UI.IViewModelTabSection.Title
    End Class


    Public Class SynthesePoint
        Inherits ViewModelBase

        Private _Label As String
        Public Property Label As String
            Get
                Return _Label
            End Get
            Set(ByVal value As String)
                OnPropertyChanging("Label")
                Dim args As New PropertyChangeEventArgs(Of String)(_Label, value)
                OnLabelChange(args)
                _Label = args.NewValue
                OnPropertyChanged("Label")
            End Set
        End Property
        Protected Overridable Sub OnLabelChange(ByVal args As PropertyChangeEventArgs(Of String))
            RaiseEvent LabelChange(Me, args)
        End Sub
        Public Event LabelChange As PropertyChangeEventHandler(Of String)

        Private _Value As Double
        Public Property Value As Double
            Get
                Return _Value
            End Get
            Set(ByVal value As Double)
                OnPropertyChanging("Value")
                Dim args As New PropertyChangeEventArgs(Of Double)(_Value, value)
                OnValueChange(args)
                _Value = args.NewValue
                OnPropertyChanged("Value")
            End Set
        End Property
        Protected Overridable Sub OnValueChange(ByVal args As PropertyChangeEventArgs(Of Double))
            RaiseEvent ValueChange(Me, args)
        End Sub
        Public Event ValueChange As PropertyChangeEventHandler(Of Double)

        Private _Position As Integer
        Public Property Position As Integer
            Get
                Return _Position
            End Get
            Set(ByVal value As Integer)
                OnPropertyChanging("Position")
                Dim args As New PropertyChangeEventArgs(Of Integer)(_Position, value)
                OnPositionChange(args)
                _Position = args.NewValue
                OnPropertyChanged("Position")
            End Set
        End Property
        Protected Overridable Sub OnPositionChange(ByVal args As PropertyChangeEventArgs(Of Integer))
            RaiseEvent PositionChange(Me, args)
        End Sub
        Public Event PositionChange As PropertyChangeEventHandler(Of Integer)

        Private _ContextMenuCommands As ObservableCollection(Of DelegateCommand)
        Public Property ContextMenuCommands As ObservableCollection(Of DelegateCommand)
            Get
                Return _ContextMenuCommands
            End Get
            Set(ByVal value As ObservableCollection(Of DelegateCommand))
                OnPropertyChanging("ContextMenuCommands")
                Dim args As New PropertyChangeEventArgs(Of ObservableCollection(Of DelegateCommand))(_ContextMenuCommands, value)
                OnContextMenuCommandsChange(args)
                _ContextMenuCommands = args.NewValue
                OnPropertyChanged("ContextMenuCommands")
            End Set
        End Property
        Protected Overridable Sub OnContextMenuCommandsChange(ByVal args As PropertyChangeEventArgs(Of ObservableCollection(Of DelegateCommand)))
            RaiseEvent ContextMenuCommandsChange(Me, args)
        End Sub
        Public Event ContextMenuCommandsChange As PropertyChangeEventHandler(Of ObservableCollection(Of DelegateCommand))

    End Class
End Namespace
